package HanShuFangFa;

import java.util.Arrays;
import java.util.Scanner;

public class exercise04 {
    public static void showMenu(){
        System.out.println("--------------------欢迎进入RBAC系统--------------------");
        System.out.println("按1.查询所有部门");
        System.out.println("按2.根据ID查询部门");
        System.out.println("按3.根据名称查询部门");
        System.out.print("input your choice number  ：");
    }

    public static void getAllDepartment(String[] depts){
        System.out.println("search  result: "+Arrays.toString(depts));
    }

    public static void findById(String[] depts, Scanner scanner04){
        System.out.println("input id :");
        int i = scanner04.nextInt();
        for (String num : depts){   //num="1-生活部"
            String[] arr = num.split("-");  // arr=[1,"生活部"]
            if(i == Integer.parseInt(arr[0])){  // 把数组的1强制转化为int型的1
                System.out.println("search  result: "+arr[1]); // 匹配相同的数字之后，输出对应的类型（arr[1]）
            }
        }
    }

    public static void findByDepartmentName(Scanner scanner04, String[] depts){
        System.out.println("input department name :");
        String departmentName = scanner04.next();
        for (String name04 : depts){
            if (name04.contains(departmentName)){
                System.out.println("search  result :"+name04);
            }
        }
    }


    //ID Identification 唯一的标识
    public static void main(String[] args) {
        String[] depts = {"1-生活部","2-宣传部","3-礼仪部","4-财务部"};

        for(;;){
            showMenu();
            Scanner scanner04 = new Scanner(System.in);
            int i = scanner04.nextInt();
            switch (i){
                case 1:
                    getAllDepartment(depts);
                    break;
                case 2:
                    findById(depts,scanner04);
                    break;
                case 3:
                    findByDepartmentName(scanner04, depts);
                    break;
            }
        }
    }
}
